import * as mongoose from 'mongoose';
const Schema = mongoose.Schema;
export const ProductSchema = new Schema(
  {
    title: {
      // 商品标题
      type: String,
      required: true,
    },
    subtitle: {
      // 副标题
      type: String,
    },
    category: {
      // 所属的分类
      type: Schema.Types.ObjectId,
      ref: 'Category',
    },
    price: {
      // 实际价格
      type: Number,
    },
    crossedOutPrice: {
      // 划线价格
      type: Number,
    },
    imageUrl: {
      // 商品的图片
      type: String,
    },
    description: {
      // 商品描述
      type: String,
    },
    isNew: {
      // 是否新品
      type: Boolean,
      default: true,
    },
    isRecommended: {
      // 是否推荐
      type: Boolean,
      default: true,
    },
    isPremium: {
      // 是否精品
      type: Boolean,
      default: true,
    },
    order: {
      type: Number,
      default: 100,
    },
    isActive: {
      type: Boolean,
      default: true,
    },
  },
  {
    timestamps: true,
    toJSON: {
      virtuals: true,
      transform(doc, ret) {
        ret.id = ret._id;
        delete ret._id;
        delete ret.__v;
      },
    },
  },
);
